<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<?php
/**
 * Created by PhpStorm.
 * User: dapeng
 * Date: 2018/9/27
 * Time: 下午4:32
 */

//获取到用户的列表
//2、连接数据库
try{
    $pdo = new PDO("mysql:host=localhost;dbname=test","root","");
}catch (Exception $e){
    var_dump($e);
    die("连接失败");
}

//3、组装插入语句
$selectSQL  = "select * from tbl_user order by id desc";//


//4、执行插入语句
$res = $pdo->query($selectSQL);//普遍用于查询,返回的是一组结果集
?>

<table border="1">
    <thead>
    <tr>
        <th>学号</th>
        <th>姓名</th>
        <th>年龄</th>
        <th>电话</th>
        <th>性别</th>
    </tr>
    </thead>

    <tbody>

    <?php
        foreach ($res as $row){
    ?>

    <tr>
        <td><?php echo $row['id']?></td>
        <td><?php echo $row['name']?></td>
        <td><?php echo $row['age']?></td>
        <td><?php echo $row['tel']?></td>
        <td><?php echo $row['sex']?></td>
        <td><a href="edit.php?id=<?php echo $row['id']?>">编辑</a></td>
        <td><a href="del.php?id=<?php echo $row['id']?>">删除</a></td>
    </tr>

    <?php } ?>

    </tbody>
</table>
